Skip to content

Conversation

@devin-ai-integration
Copy link

Optimize OpenID configuration fetching with LRU cache

Summary

This PR optimizes the get_discovery_doc function to reduce latency and redundant network requests when creating multiple AuthClient instances. The changes include:

  • Added @lru_cache() decorator to cache discovery document responses per environment
  • Removed the session parameter dependency from get_discovery_doc
  • Always use requests.get() directly since authentication is not needed for OpenID configuration endpoints
  • Updated the call site in AuthClient.__init__ to remove the session parameter
  • Fixed the test suite by clearing cache before mocking bad responses

This optimization will significantly improve performance for applications that create multiple AuthClient instances, as the discovery document will only be fetched once per environment and then served from cache.

Review & Testing Checklist for Human

  • Verify discovery endpoints don't require session auth: Confirm that .well-known/openid_configuration/ endpoints work correctly without session-specific configurations (cookies, proxies, auth headers)
  • Test caching behavior: Create multiple AuthClient instances and verify they share the cached discovery document correctly
  • Test long-running applications: Verify that cached discovery documents don't cause issues if the actual endpoints change (though this should be rare)
  • Test custom environment URLs: Ensure caching works correctly with both predefined environments ('sandbox', 'production') and custom URLs

Notes

- Add @lru_cache() decorator to get_discovery_doc function
- Remove session parameter dependency from get_discovery_doc
- Always use requests.get() directly since auth not needed for this endpoint
- Update AuthClient.__init__ call site to remove session parameter
- Fix test to clear cache before mocking bad response
- Reduces latency and redundant network requests for multiple AuthClient instances

Co-Authored-By: abhay.aggarwal@codeium.com <abhay.aggarwal@windsurf.com>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant